b = int(input())
if 999<b<10000:
    b1 = b//10000
    b2 = b//100
    b3 = b % 100
    b4 = b % 1000
    max_b = 0
    s1 , s2, s3, s4, s5 = 0, 0, 0, 0, 0
    for d in range(1, b1+1):
        if b1 % d == 0:
            s1 = s1 +1
    if s1 == 2:
        max_b = max(max_b, b1)
    for d in range(1, b2+1):
        if b2 % d == 0:
            s2 = s2 +1
    if s2 == 2:
        max_b = max(max_b, b2)
    for d in range(1, b3+1):
        if b3 % d == 0:
            s3 = s3 +1
    if s3 == 2:
        max_b = max(max_b, b3)
    for d in range(1, b4+1):
        if b4 % d == 0:
            s4 = s4 +1
    if s4 == 2:
        max_b = max(max_b, b4)
    for d in range(1, b+1):
        if b % d == 0:
            s5 = s5 +1
    if s5 == 2:
        max_b = max(max_b, b)
    if max_b == 0:
        print('0')
    else:
        print(max_b)
else:
    print('0')
    
